<?php
	/**
	 * Created by PhpStorm.
	 * User: mybook-lhp
	 * Date: 18/3/27
	 * Time: 下午5:14
	 */

	namespace App\Utility;
	use EasySwoole\Config;


	/**
	 * redis操作类
	 * 说明，任何为false的串，存在redis中都是空串。
	 * 只有在key不存在时，才会返回false。
	 * 这点可用于防止缓存穿透
	 *
	 */
	class Redis
	{
		private static $instance;
		private $con;

		static function getInstance(){
			if(!isset(self::$instance)){
				self::$instance = new Redis();
			}
			return self::$instance;
		}

		function __construct()
		{
			$conf = Config::getInstance()->getConf("REDIS");
			$this->con = new \Redis();
			$this->con->connect($conf['HOST'],$conf['PORT']);
			$this->con->auth($conf['AUTH']);
			$this->con->setOption(\Redis::OPT_SERIALIZER,\Redis::SERIALIZER_PHP);
		}

		function getConnect(){
			return $this->con;
		}
	}